﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Yubis.Data.Properties;

namespace Yubis.Data.SqlServer
{
    public class Language : ILanguage
    {

        public Language()
        { 
        
        }
        
        public void SetDefaultLanguage(short localeId)
        {
            SqlConnection connection = new SqlConnection(Settings.Default.ConnectionString);
            connection.Open();

            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandText = "INSERT INTO Language_Available( LocaleId, IsDefault ) VALUES ( @LocaleId, 1 )";
            command.Parameters.Add("@LocaleId", SqlDbType.SmallInt);
            command.Parameters["@LocaleId"].Value = localeId;
            command.ExecuteNonQuery();

            connection.Close();
        }

        public Dictionary<short, string> GetLabels(Guid resourceId)
        {
            Dictionary<short, string> returnValue = new Dictionary<short, string>();

            SqlCommand command = new SqlCommand();
            command.Connection = new SqlConnection(Yubis.Data.Properties.Settings.Default.ConnectionString);
            command.CommandText = "SELECT LocaleId, Name FROM Language_Translation WHERE (ResourceId = @ResourceId)";

            command.Parameters.Add("@ResourceId", SqlDbType.UniqueIdentifier);
            command.Parameters["@ResourceId"].Value = resourceId;
            
            
            command.Connection.Open();
            SqlDataReader data = command.ExecuteReader();


            
            if (data.HasRows)
            {
                while (data.Read())
                {
                    returnValue.Add(
                        Convert.ToInt16(data["LocaleId"]),
                        Convert.ToString(data["Name"]));
                }
            }


            return returnValue;
        
        }

        public Dictionary<short, string> GetLabels(Guid resourceId, short localeId)
        {
            Dictionary<short, string> returnValue = new Dictionary<short, string>();

            return returnValue;
        }

        //public void SetLabels(LanguageTranslationData translationData)
        //{ 
        
        //}

    }
}
